package router

import (
	"gforum/controller"
	"gforum/middlewares"
)

func setUpPostsRouter() {
	posts := api.Group("/posts")
	// /api/posts
	{
		posts.GET("/", controller.GetAllPosts)
	}

	postsAuth := posts.Group("").Use(middlewares.AuthRequired(), middlewares.PostPostAllowed())
	// /api/posts 需要鉴权
	{
		postsAuth.POST("/", controller.Post)
	}

	byID := posts.Group("/:id")
	// /api/posts/{id}
	{
		byID.GET("/", controller.GetPostsByID)
		byID.GET("/like", controller.GetLikes)
	}

	byIDAuth := byID.Group("").Use(middlewares.AuthRequired())
	// /api/posts/{id} 需要鉴权
	{
		byIDAuth.PUT("/", middlewares.EditPermissionRequired(), controller.EditPostByID)
		byIDAuth.DELETE("/", middlewares.EditPermissionRequired(), controller.DeletePostByID)
		byIDAuth.PUT("/like", controller.Like)
	}

	search := api.Group("/search")
	{
		search.GET("/", controller.SearchPosts)
	}
}
